###############################################################################-
# Author: Pietryka
# Contact: matthew.pietryka@gmail.com
# Purpose: code used in multiple scripts for formatting plots and tables
# Notes:
###############################################################################-


library(extrafont)
library(showtext)
loadfonts(device = "win")


the_typeface <-  "Arial Narrow"
font_add(the_typeface, "arialnarrow.ttf")
font_add("Arial Narrow Bold", "arialnarrow_bold.ttf")
hrbrthemes::update_geom_font_defaults(the_typeface)



windowsFonts(sans = the_typeface)


## ggplot theme -------------------------------------

grid_color <- "grey90"


format_plot <- function(the_size, ...){
  theme_minimal(...) +
  theme(
    text = element_text(family = the_typeface),
    axis.title = element_text(family = the_typeface),
    panel.grid.major =  element_line(colour = grid_color, linewidth  = 0.5),
    panel.grid.minor =  element_blank()
  )
}



# outcome labels ===============================


outcome_labels_df <- tribble(
  ~"var",            ~"label",
  "n_identical",      "Number of Identical Elections",
  "pct_identical_2016",         "Percent Identical, 2016",
  "pct_identical_2018",         "Percent Identical, 2018",
  "pct_identical_2020",         "Percent Identical, 2020"
)


# Figures 4 and  5 defaults =====================================

roommate_abstain_lab = "Roommate abstained in 2016"
roommate_vote_lab = "Roommate voted in 2016"
parents_abstain_lab = "Parents never voted, 2008-14"
parents_vote_lab = "Parents always voted, 2008-14"


se_plot_x_labs <-  c(
  `5` = roommate_abstain_lab ,
  `4` = roommate_vote_lab,
  `2` = parents_abstain_lab,
  `1` = parents_vote_lab
)

se_plot_shapes <- c(
  `5` = 21,
  `4` = 19,
  `2` = 24,
  `1` = 17
)
